package com.cjb.usercenter.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/redis")
public class RedisController {

   @Autowired
    private StringRedisTemplate stringRedisTemplate;


   @RequestMapping("/set")
   @ResponseBody
   public String set(String key,String value){
        try{
             stringRedisTemplate.opsForValue().set(key,value);
             return "success";
        }catch(Exception exception){
            return "error";
        }
   }



    @RequestMapping("/get")
    @ResponseBody
    public String get(String key){
        try{
            String ret = stringRedisTemplate.opsForValue().get(key);
            return ret;
        }catch(Exception exception){
            return "error";
        }
    }
}
